#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu
    reload(mu)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class CheckExcludeDefaultShader(CheckBase):
    def __init__(self):
        super(CheckExcludeDefaultShader, self).__init__()
        pass
        self.default_type = ['lambert','blinn', 'phong', 'phoneE', 'surfaceShader', 'anisotropic', 'layeredShader', 'rampShader']

    def check(self):
        error_list = []
        all_mesh = mu.list_all_mesh()
        for mesh in all_mesh:
            sg_list = mu.getSGsFromObj(mesh)
            if sg_list:
                shader = cmds.listConnections(sg_list[0] + '.surfaceShader', c=0, d=1, s=1, p=0)
                if shader:
                    shader_type = cmds.objectType(shader[0])
                    if shader_type in self.default_type:
                        error_list.append(shader[0])
        if error_list:
            result_log = u'Error:%s\n' % error_list
        else:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        pass

